include("../../static/js/config.js");
include("../../static/js/common.js");

$(function () {

    var form;
    layui.use(['laydate', 'form'], function () {
        form = layui.form;
        var laydate = layui.laydate;

        laydate.render({
            type: 'datetime',
            elem: '#createDate',
            format: 'yyyy-MM-dd HH:mm:ss'
        });

        form.on('submit(update)', function(data){
            var id = $("#id").val();
            var name = $("#name").val();
            var url = $("#url").val();

            request("/admin/authority/update", {id:id, name:name, url:url}, function (data) {
                if (data.code == 200){
                    layer.msg("操作成功", {icon: 1});
                    setTimeout(function () {
                        if (window.parent){
                            window.parent.layer.closeAll();
                            window.parent.location.reload();
                        }
                    }, 3000);
                } else {
                    layer.msg(data.msg, {icon: 5});
                }
            });
            return false;
        });

        init();
    });


    function init() {
        request('/admin/authority/detail', {id: getParam('id')}, function(res){
            if (res.code == 200){
                $('#id').val(res.data.id);
                $('#url').val(res.data.url);
                $('#name').val(res.data.name);
                $('#createDate').val(res.data.createDate);
            } else {
                layer.msg(res.msg, {icon: 5});
            }
        });
    }
})